package com.proj.android.canyondefense.core.impl;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import android.content.res.AssetManager;
import android.os.Environment;
import com.proj.android.canyondefense.core.base.IFileIO;

public class AndroidFileIO implements IFileIO {
	private AssetManager _assetMgr;
	private String _externalStoragePath;
	
	public AndroidFileIO(AssetManager assets) {
		this._assetMgr = assets;
		this._externalStoragePath = Environment.getExternalStorageDirectory().getAbsolutePath() + File.pathSeparator;
	}

	public InputStream readAsset(String fileName) throws IOException {
		return _assetMgr.open(fileName);
	}

	public InputStream readFile(String fileName) throws IOException {
		return new FileInputStream(_externalStoragePath + fileName);
	}

	public OutputStream writeFile(String fileName) throws IOException {
		return new FileOutputStream(_externalStoragePath + fileName);
	}

}
